Repository navigation
fix(run): count a failed re-extraction in both front-ends - #204
Open
harsh-thakkar7 wants to merge 1 commit into
Open
harsh-thakkar7 wants to merge 1 commit into
harsh-thakkar7 wants to merge 1 commit into
Conversation
This was referenced Oct 10, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #178
The repro first, as the issue asks
The issue presumed a live repro (a fake host that stalls once, then errors on re-extraction) was the first half of the work.
tests/test_reextract_accounting.pyis exactly that: a loopback aiohttp host that trickles at ~5 KB/s against a declared 65536-byte body, extraction stubbed at themoon_extractboundary to succeed once and fail on the re-extraction. The stall constants are monkeypatched down (grace 90s → 1s, 50 MB file gate → 0, 4 MB read chunk → 1 KB) so production's detector fires inside a test; everything else — including the realdownload_fileand its stall kill — is the shipping code path.Proven red on
main: the engine test times out asserting_runningis still set after 15 s ("the run never finished: the failed re-extraction was never counted and the run waited for it forever"), and the CLI test observes four extraction attempts behind 1s/2s/4s of backoff before the link is counted at all.What the repro found that the issue's call-site reading did not
The issue says both front-ends wait forever. The engine does. The CLI does not, and the difference matters for the fix:
not is_reexcludes the record, no othermark_done()is reachable,n_donenever reaches the link count → hang. As described.rec.stall_killsis never incremented on a stall kill (only the engine does that, atmoon_engine.py:255), sois_reis dead code there. A re-extraction is re-queued as if it were a first attempt and burns the full retry budget — three extra extraction attempts behind 7 s of backoff — before it is counted. No hang, but exactly the "burns the retry budget twice" outcome the guard exists to prevent, plus the report'sStall killssum permanently reads 0 for CLI runs.So the fix is two changes per front-end, not one.
Change (3 hunks, no behaviour change beyond the accounting)
moon_engine.py— the fail branch (one line plus comment): dropnot is_re. A failed re-extraction is counted as onefail, lands infailed_urls, and gets its single terminalmark_done_fn(). The retry branch above still excludesis_re, so it never burns the budget twice.moon_cli.py— the stall branch: incrementrec.stall_kills += 1, mirroring the engine's kill site. This is what makesis_retrue at all in the CLI, which fixes the report field and the retry-budget burn.moon_cli.py— the fail branch: dropnot is_reand route the counter byis_re. This second part is not cosmetic:mark_extractionis a no-op for an already-counted record (guard atmoon_engine.py:169), and a re-extraction was already counted as extracted on its first pass — routing it throughmark_extractionleaves_dl_doneshort of_dl_total,all_doneunset, and the CLI hanging via a different mechanism. The terminal count for a re-extraction ismark_download_end(False); a first-attempt extraction failure still usesmark_extraction. I found this by watching the CLI test stay red after the naive one-line fix — it is why the repro came first.Design argument (per the issue: count the drop as a
fail)Over giving re-extractions their own retry budget: a re-extraction that fails has already spent its stall kills and its retries on the first pass; re-budgeting it lets one record occupy a worker lane roughly twice as long as any other, and the only thing actually broken here is the accounting — the record reaches a terminal state and nobody tells the run. Nothing about download behaviour needs to change for the hang to go away, so I changed nothing about download behaviour.
Verification
main(hang after 15 s / four attempts behind backoff), green with the fix — the same run ofpytest tests/ -qflips 2 → 0 failurespytest tests/ -q→ 172 passed (170 before), no browser, no network beyond loopback; the new file adds ~3 sruff check .→ cleantest_no_chrome.py's extraction-failure and retry assertions, which share these branchesHonest notes
dl_doneshort (it counts no download end — consistent with its own first-attempt extraction failures, wheredl_doneis also 0), while the CLI'smark_download_end(False)increments it. The CLI has no choice:mark_extractioncannot count the record twice. The engine could_inc("_dl_done")for symmetry; I left it because the engine's own convention for an extraction-time terminal state isdl_done == 0, and changing it would move numbers in the GUI for a case this issue is not about.moon_engine.py:396increments_url_donefor every dequeued entry, so a stall-killed link increments it twice (once per pass) against_url_total. That inflatesextract_donein the GUI for every stall kill. It is a separate bug from the accounting hang and fixing it would change snapshot numbers, so it is out of scope here — flagging it so it is not lost.